package ru.gerunn.study.spring.jdbc;

import java.util.Date;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String[] args) {

		ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao-context.xml");
		UserManager userManager = (UserManager) ctx.getBean("userManagerImpl");
		
		Long time = new Date().getTime();

		User user = new User();
		user.setUsername(time.toString());
		user.setName(time.toString());

		userManager.insertUser(user);

		System.out.println("User inserted!");

		user = userManager.getUser("johndoe");

		System.out.println("\nUser fetched!" + "\nId: " + user.getId() + "\nUsername: " + user.getUsername() + "\nName: " + user.getName());

		List<User> users = userManager.getUsers();

		System.out.println("\nUser list fetched!" + "\nUser count: " + users.size());

	}
}